package org.chispa.api.visitors;

import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import org.chispa.api.query.ParamWrapper;
import org.chispa.api.util.BadSyntaxException;
import org.chispa.api.util.NoSuitableVisitorException;

class NumericExpVisitorBridge extends SingleParamVisitor<String, String> {
	
	private NumericParamVisitor wrapped;

	NumericExpVisitorBridge(NumericParamVisitor wrapped) {
		super(wrapped.blockCipher, wrapped.spec, wrapped.ivSpec);
		this.wrapped=wrapped;
	}

	@Override
	public String visitEncrypt(ParamWrapper<String, String, String> wrap) {
		try {
			return wrapped.doEncrypt(wrap.getWrappedParam().getBytes());
		} catch (Exception e) {
			System.err.println(e.getLocalizedMessage());
			return null;
		} 
	}

	@Override
	public String visitHash(ParamWrapper<String, String, String> wrap)
			throws NoSuitableVisitorException, NoSuchAlgorithmException, BadSyntaxException {
		return visitHashExpr(wrap,new HashMap<String,String>());
	}

	@Override
	public String visitHashExpr(ParamWrapper<String, String, String> wrap,
			Map<String, String>parameters) throws BadSyntaxException,
			NoSuitableVisitorException {
		return wrapped.visitHashExpr(wrap,parameters);
	}

	@Override
	public String visitDecrypt(String encrypted) {
		return wrapped.visitDecrypt(encrypted);
	}

}
